namespace generator
{
    public static class StringExtensions
    {
        public static string StripRight(this string s, string stringToStrip) {
            var index = s.IndexOf(stringToStrip);
            if (index + stringToStrip.Length == s.Length) {
                return s.Substring(0, s.Length - stringToStrip.Length);
            }
            return s;
        }

        public static string SubstringAfterLast(this string s, string searchString) {
            var indexOfLastBackslash = s.LastIndexOf(searchString);
            if (indexOfLastBackslash != -1) {
                s = s.Substring(indexOfLastBackslash + 1, s.Length - indexOfLastBackslash - 1);
            }
            return s;
        }

        public static string SubstringUpTo(this string s, string searchString) {
            var index = s.IndexOf(searchString);
            if (index == -1) {
                return s;
            }
            return s.Substring(0, index);
        }

        public static string SubstringUpToLast(this string s, string searchString) {
            var index = s.LastIndexOf(searchString);
            if (index == -1) {
                return s;
            }
            return s.Substring(0, index);
        }

        public static string FirstLetterToUppercase(this string s) {
            if (s.Length == 0) {
                return s;
            }
            return s.Substring(0, 1).ToUpper() + s.Substring(1, s.Length - 1);
        }
    }
}